import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)


const state = {
    username: "jack",
    goodCount: 20
}

const actions = {
    setUser({commit}, data){
        commit("setUser", data)
    },
    getUser(store, data){
        console.log("集中式状态管理：", store)
        store.commit("getUser", data)
    }
}

const mutations = {
    setUser(state, data){
        state.username = data
    },
    getUser(state, data){
        return state[data]
    },
}

export default new Vuex.Store({
    actions,
    mutations,
    state
})

